package com.cn.wanxi.service;

import com.cn.wanxi.IO.FileModelIO;
import com.cn.wanxi.IOModel.NewsTypeIOModel;
import com.cn.wanxi.model.NewsTypeModel;
import com.cn.wanxi.util.IOUtil;

import java.util.List;

public class NewsTypeService {
    public List<NewsTypeModel> getNewsTypes(){
        FileModelIO.writeData(IOUtil.NEWTYPEPATH.getPath(),new NewsTypeIOModel().toString());
        String result = FileModelIO.readData(IOUtil.NEWTYPEPATH.getPath());
        result = result.substring(result.indexOf("[")+1,result.lastIndexOf("]"));
        System.out.println(result);
        String[] names = result.split(",");
        NewsTypeModel newsTypeModel = new NewsTypeModel();
        for (int i = 0; i < names.length; i++) {
            NewsTypeModel newsType = new NewsTypeModel();
            newsType.setName(names[i].trim());
            System.out.println(names[i].trim());
            newsTypeModel.list.add(newsType);
        }
        return newsTypeModel.list;
    }

    public static void main(String[] args) {
        new NewsTypeService().getNewsTypes();
    }
}
